<?php

use Gregwar\Captcha\CaptchaBuilder;

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

//相册

Route::get('/albums', 'albumsController@index')->name('home');

Route::get('/home', 'albumsController@index');

//相册资源路由
Route::resource('albums','AlbumsController');

//相片资源路由
Route::resource('photos','PhotosController');

Route::post('photos/store','PhotosController@store');

Route::get('/', function () {
    return view('welcome');
});

// 验证码输出, 验证码组件
Route::get('captch', 'Auth\AuthController@captch');

// 后台首页的路由规则
Route::get('/admin', 'AdminController@index');

Route::resource('user', 'UserController');

// 隐式路由
Route::controller('/db', 'DbController');

Route::controller('/mvc', 'Home\MVCController');

Route::resource('/b','Home\BlogController');

Route::post('/b/pre_mk', 'Home\BlogController@pre_mk');

// 认证路由...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');


// 注册路由...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

/*Route::get('/admin/index', function(){
	return view('admin.index');
});

Route::get('/admin/welcome', function(){
	return view('admin.welcome');
});

Route::get('/admin/user', function(){
	return view('admin.userlist');
});*/

Route::group(['prefix'=>'admin'],function(){
	Route::get('index', function(){
		return view('admin.index');
	});

	Route::get('welcome', function(){
		return view('admin.welcome');
	});

	Route::resource('cate', 'Admin\CateController');
	Route::get('catelist', 'Admin\CateController@list');

	Route::resource('user', 'Admin\UserController');
});

// 验证码
Route::any('captcha-test', function()
{
    if (Request::getMethod() == 'POST')
    {
        $rules = ['captcha' => 'required|captcha'];
        $validator = Validator::make(Input::all(), $rules);
        if ($validator->fails())
        {
            echo '<p style="color: #ff0000;">Incorrect!</p>';
        }
        else
        {
            echo '<p style="color: #00ff30;">Matched :)</p>';
        }
    }

    $form = '<form method="post" action="captcha-test">';
    $form .= '<input type="hidden" name="_token" value="' . csrf_token() . '">';
    $form .= '<p>' . captcha_img() . '</p>';
    $form .= '<p><input type="text" name="captcha"></p>';
    $form .= '<p><button type="submit" name="check">Check</button></p>';
    $form .= '</form>';
    return $form;
});

// Route::get('capt', function(){
// 	$builder = new CaptchaBuilder;
// 	$builder->build();
// 	header('Content-type: image/jpeg');
// 	$builder->output();
// });

//购物车

Route::resource('shop', 'Home\ShopController');
Route::controller('shop', 'Home\ShopController');
Route::get('/addcart/{id}', 'Home\ShopController@addcart');
Route::get('/cart', 'Home\ShopController@cart')->name('cart');
Route::get('/del', 'Home\ShopController@destroy');

